package com.lagou.scala.test.Q5

import akka.actor.{Actor, ActorRef}

class Worker(master: ActorRef, name: String) extends Actor {
  val random = scala.util.Random
  override def receive: Receive = {
    case Register =>
      master ! Register(name)
    case Ack =>
      val seconds = random.nextInt(10)
      println(s"$name 收到确认, 等待 $seconds 秒...")
      Thread.sleep(seconds * 1000)
      master ! Beat(name)
  }
}
